<template>
  <div>
    <search-view></search-view>
    <h2>今日菜单</h2>

    <div class="greensBox">
      <div class="titleBox">
        <van-tabs v-model="active" @click="menu" sticky animated>
          <van-tab :title="item.name" v-for="item in list" :key="item.id" >
           
          </van-tab>
        </van-tabs>
      </div>
      <div class="shadowBox">
        <span @click="shadow">全部</span> 
        <van-popup
          v-model="show"
          closeable
          position="bottom"
          :style="{ height: '80%' }"
        >
        <h3>菜单分类</h3>
        <ul>
          <li v-for="(item,index) in list" :key="item.id" @click="xianshi(index)">{{item.name}}</li>
        </ul>
        </van-popup>
      </div>
    </div>
      <greens-view :list2="list2"></greens-view>
  </div>
</template>

<script>
import SearchView from "../homeview/components/SearchView.vue";
import GreensView from './components/GreensView.vue';
// import { Toast } from 'vant';
export default {
  name: "EatView",
  components: {
    SearchView,
    GreensView
  },
  data() {
    return {
      active: 0,
      list: [],
      list2:[],
      show:false,
    };
  },
  created() {
    this.$http.getEat().then((res) => {
      this.list = res.data.data.list;
      // console.log(this.list);
    });
    this.$http.getWhatEat("lk01.json").then(res2 => {
        this.list2 = res2.data.data.big_recommend.list;
      })
  },
  methods:{
    shadow(){
      this.show = true
    },
    menu(index){
      let str = "lk0";
      if(index > 9){
        str = "lk";
      }
      // console.log(index);
       this.$http.getWhatEat(str+(index+1)+".json").then(res2 => {
        // console.log(res2.data.data.big_recommend.list);
        this.list2 = res2.data.data.big_recommend.list;
      })
    },
    xianshi(index){
      console.log(index);
      this.active = index
       this.menu(index)
      this.show = false
    }
  }
};
</script>

<style scoped lang="scss">
.greensBox{
  display: flex;
  justify-content: space-around;
  align-content: center;
  span{
    font-size: .28rem;
  }
  h3{
    margin-top: 1rem;
    font-size: .28rem;
  }
  .shadowBox{
     ul{
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    li{
      font-size: .28rem;
      width: 20%;
      height: .6rem;
      line-height: .6rem;
      text-align: center;
      border: .01rem solid #E4E4E4;
      border-radius: .4rem;
      margin-top: .2rem;
    }
  }
  }
 
}
.titleBox {
  width: 80%;
  margin-left: 0.2rem;
}
h2 {
  font-size: 0.4rem;
  position: relative;
  margin-left: 0.5rem;
  &::before {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translate(-0.2rem, -50%);
    content: "";
    width: 0.1rem;
    height: 0.6rem;
    background: #639633;
  }
}
.scroll-wrapper {
  position: relative;
  width: 90%;
  margin: 0.2rem auto;
  white-space: nowrap;
  border: 3px solid #42b983;
  border-radius: 5px;
  overflow: hidden;
}
.scroll-content {
  display: inline-block;
}
.scroll-item {
  height: 50px;
  line-height: 50px;
  font-size: 24px;
  display: inline-block;
  text-align: center;
  padding: 0 10px;
}
</style>